﻿Imports Seuss.EnterpriseLibrary.DataAccess
Imports Seuss.EnterpriseLibrary.BusinessLogic
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Data

Partial Class Consulta_AL_InfoEcon
    Inherits System.Web.UI.Page
    Dim FilialPremium As String
    Dim CodigoUniversitario As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Expires = -1
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("cache-control", "private")
        Response.CacheControl = "no-cache"
        If Not Page.IsPostBack Then
            FilialPremium = Request.QueryString("Filial")
            CodigoUniversitario = Request.QueryString("CodUniv")
            lblCodUniv.Text = CodigoUniversitario
            lblBDPremium.Text = FilialPremium
            lblperiodo.Text = 201202
            Call CargarProgramacionEconomica(lblperiodo.Text, lblCodUniv.Text, lblBDPremium.Text)
            Call CapturaDeuda(lblBDPremium.Text)
            Using Seguridad As New BLL_Administracion
                Seguridad.Set_Transaccion_Insert(Nothing, 100401, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Consulta Pagina Movil", "/Pagina|" + My.Request.Url.Segments(My.Request.Url.Segments.Length - 1).ToString))
            End Using
        End If
    End Sub

    Protected Sub adelante(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnadelante.Click
        Dim nAnio As Integer, nAnio1 As Integer
        Dim sSem As String = "", ssem1 As String = ""

        nAnio = CInt(Left(lblperiodo.Text, 4))
        sSem = CStr(Right(lblperiodo.Text, 2))

        Select Case sSem
            Case Is = "00"
                ssem1 = "01"
                nAnio1 = nAnio
            Case Is = "01"
                ssem1 = "02"
                nAnio1 = nAnio
            Case Is = "02"
                ssem1 = "00"
                nAnio1 = nAnio + 1
        End Select
        lblperiodo.Text = CStr(nAnio1) & CStr(ssem1)
        Call CargarProgramacionEconomica(lblperiodo.Text, lblCodUniv.Text, lblBDPremium.Text)
    End Sub
    Protected Sub atras(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnatras.Click
        Dim nAnio As Integer, nAnio1 As Integer
        Dim sSem As String = "", ssem1 As String = ""

        nAnio = CInt(Left(lblperiodo.Text, 4))
        sSem = CStr(Right(lblperiodo.Text, 2))

        Select Case sSem
            Case Is = "00"
                ssem1 = "02"
                nAnio1 = nAnio - 1
            Case Is = "01"
                ssem1 = "00"
                nAnio1 = nAnio
            Case Is = "02"
                ssem1 = "01"
                nAnio1 = nAnio
        End Select
        lblperiodo.Text = CStr(nAnio1) & CStr(ssem1)
        Call CargarProgramacionEconomica(lblperiodo.Text, lblCodUniv.Text, lblBDPremium.Text)
    End Sub

    Private Sub CargarProgramacionEconomica(ByVal cPrdDescripcion As String, ByVal CodUniv As String, ByVal cPerJuridica As String)
        Dim ldr As New List(Of IDataReader)
        Dim DivPrincipal As New StringBuilder
        Dim BdPremium As String
        BdPremium = CapturaFilialPremium(cPerJuridica)
        DivPrincipal.Append("<table  style='width:100%;'>")

        DivPrincipal.Append("<tr style='color:#FFFFFF'>")
        DivPrincipal.Append("   <td style='background-color:#666666;font-size:10px;width:35%'>Descripción</td>")
        DivPrincipal.Append("   <td style='background-color:#666666;font-size:10px;'>Estado</td>")
        DivPrincipal.Append("   <td style='background-color:#666666;font-size:10px;'>Monto</td>")
        DivPrincipal.Append("   <td style='background-color:#666666;font-size:10px;'>Cuota</td>")
        DivPrincipal.Append("   <td style='background-color:#666666;font-size:10px;'>Vencimiento</td>")
        DivPrincipal.Append("</tr>")

        Using ObjPool As New PoolDbCommand()
            Dim ObjUsuario As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(ObjUsuario.Get_CtasCte_By_cPerCodigo(CodUniv, cPrdDescripcion, BdPremium), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldr, True)
            ObjUsuario = Nothing
            While ldr(0).Read
                DivPrincipal.Append("<tr>")
                DivPrincipal.Append("   <td style='font-size:8px;width:35%;text-align:left'>" + ldr(0).Item("descserv").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:8px;width:15%;'>" + ldr(0).Item("estadod").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:8px;text-align:right'>" + ldr(0).Item("monto").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:8px;'>" + ldr(0).Item("nrocuota").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:8px;width:25%;'>" + ldr(0).Item("udp").ToString + "</td>")
                DivPrincipal.Append("</tr>")
            End While
        End Using

        DivPrincipal.Append("</table>")
        lblProgramacion.Text = DivPrincipal.ToString
    End Sub

    Private Function CapturaFilialPremium(ByVal cPerJuridica As String) As String
        Dim lDrd As New List(Of IDataReader)
        Dim FilialPremium As String = ""

        Using objPool As New PoolDbCommand()
            Dim objDal As New DAL_Kiosco(objPool.Database)
            objPool.AddDbCommand(objDal.Get_cPerIdeNumero(cPerJuridica, 90001), PoolDbCommand.PoolDbCommandResultType.Query)
            objPool.Pooling(Nothing, lDrd, True)
            If lDrd.Count > 0 Then
                If lDrd(0).Read Then
                    FilialPremium = lDrd(0).Item("cPerIdeNumero").ToString
                End If
            End If
            lDrd(0).Close()
            lDrd(0) = Nothing
        End Using
        Return FilialPremium
    End Function

    Private Sub CapturaDeuda(ByVal cPerJuridica As String)
        Dim BdPremium As String
        BdPremium = CapturaFilialPremium(cperjuridica)

        Dim ldr As New List(Of IDataReader)
        Using ObjPool As New PoolDbCommand()
            Dim ObjUsuario As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(ObjUsuario.Get_DeudaProgramadayMorosa_By_cPerCodigo(CodigoUniversitario, BdPremium), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldr, True)
            ObjUsuario = Nothing
            If ldr(0).Read Then
                lbldprog.Text = "&nbsp&nbspS/. " & ldr(0).GetValue(0)
                lbldmorosa.Text = "&nbsp&nbspS/. " & ldr(0).GetValue(1)
            End If
        End Using

    End Sub
End Class
